<?php

namespace App\Http\Model;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class RoomDynamicLog extends Base
{
    protected $table = "room_dynamic_log";


    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }

    public function createRoomDyLog($room_id, $dynamic_id, $end_time)
    {
        $roomDyLog = DB::table($this->table)->where('room_id',$room_id)->first();
        if ($roomDyLog){
            return DB::table($this->table)->where('room_id',$room_id)->update([
                'dynamic_id' => $dynamic_id,
                'created_at' => time(),
                'start_time' =>date('Y-m-d H:i:s', time()),
                'end_time' => $end_time
            ]);
        }
        return DB::table($this->table)->insertGetId([
            'room_id' => $room_id,
            'dynamic_id' => $dynamic_id,
            'created_at' => time(),
            'start_time' => date('Y-m-d H:i:s', time()),
            'end_time' => $end_time
        ]);
    }
}
